package com.gitee.ywj1352.lerning.ag.common.handler;

import com.gitee.ywj1352.lerning.ag.common.constants.StatusCode;
import com.gitee.ywj1352.lerning.ag.common.exception.BaseException;
import com.gitee.ywj1352.lerning.ag.common.vo.BaseResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by ywj on 2018/2/8.
 */
@ControllerAdvice("com.gitee.ywj1352.learning.ag.uc.controller")//意思是controller的通知类
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(BaseException.class)//统一的异常处理类
    public BaseResponse baseExceptionHandler(HttpServletResponse response,BaseException baseException){
        return new BaseResponse(StatusCode.BaseException.toCode(),baseException.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public BaseResponse otherExceptionHandler(HttpServletResponse response,BaseException baseException){
        return new BaseResponse(StatusCode.OtherException.toCode(),baseException.getMessage());
    }




}
